<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item labelWidth="100" label="联系电话：" prop="contactPhoneNumber">
        <el-input v-model="form.contactPhoneNumber" placeholder="请输入联系电话" />
      </el-form-item>
      <el-form-item labelWidth="100" label="联系邮箱：" prop="contactEmail">
        <el-input v-model="form.contactEmail" placeholder="请输入联系邮箱" />
      </el-form-item>
      <el-form-item labelWidth="100" label="合作电话：" prop="cooperationPhoneNumber">
        <el-input v-model="form.cooperationPhoneNumber" placeholder="请输入合作电话" />
      </el-form-item>
      <el-form-item labelWidth="100" label="客服服务电话：" prop="customerServicePhoneNumber">
        <el-input v-model="form.customerServicePhoneNumber" placeholder="请输入客服服务电话" />
      </el-form-item>
      <el-form-item labelWidth="100" label="租先知风控API Appid：" prop="reportZuxianzhiAppid">
        <el-input v-model="form.reportZuxianzhiAppid"></el-input>
      </el-form-item>
      <el-form-item labelWidth="100" label="租先知风控API Appsecret：" prop="reportZuxianzhiSecret">
        <el-input v-model="form.reportZuxianzhiSecret"></el-input>
      </el-form-item>
      <el-form-item labelWidth="100" label="风控检测收费：" prop="privilegeAmount">
        <el-input v-model="form.privilegeAmount"></el-input>
      </el-form-item>
      <el-form-item labelWidth="100" label="风控等级" prop="privilegeLevel">
        <el-select v-model="form.privilegeLevel" required placeholder="请选择" clearable>
          <el-option
            v-for="dict in dictList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { listPlatforminfo, getPlatforminfo, delPlatforminfo, addPlatforminfo, updatePlatforminfo } from "@/api/system/platforminfo"

export default {
  name: "Platforminfo",
  data() {
    var ruleValidateAmount = (rule, value, callback) => {
			if(!this.form.id || value){
				if(!/^[0-9]+(\.[0-9]{2}})?$/.test(value)){
					callback(new Error('请输入正确的金额'));
				}
			}
			callback();
		}
    return {
      dictList:[
        // {
        //   value:'L',
        //   label:"基础版"
        // },
        {
          value:'M',
          label:"标准版"
        },
        {
          value:'H',
          label:"高级版"
        }
        // {
        //   value:'Hv2',
        //   label:"高级版V2"
        // },
        // {
        //   value:'Hv3',
        //   label:"高级版V3"
        // }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台信息表格数据
      platforminfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        runningStatus: null,
        contactPhoneNumber: null,
        contactEmail: null,
        cooperationPhoneNumber: null,
        customerServicePhoneNumber: null,
        reportZuxianzhiAppid: null,
        reportZuxianzhiSecret: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        privilegeAmount:[
          { validator: ruleValidateAmount, message: '请输入正确的金额', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询平台信息列表 */
    getList() {
      this.loading = true
      listPlatforminfo(this.queryParams).then(response => {
        this.platforminfoList = response.rows
        this.total = response.total
        this.loading = false
        this.form = response.rows[0]
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createTime: null,
        updateTime: null,
        runningStatus: null,
        contactPhoneNumber: null,
        contactEmail: null,
        cooperationPhoneNumber: null,
        customerServicePhoneNumber: null,
        reportZuxianzhiAppid: null,
        reportZuxianzhiSecret: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加平台信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getPlatforminfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改平台信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlatforminfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addPlatforminfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除平台信息编号为"' + ids + '"的数据项？').then(function() {
        return delPlatforminfo(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/platforminfo/export', {
        ...this.queryParams
      }, `platforminfo_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
